var pageIndex = 1
var pageSize = 8
var dataSize = getAdminAll()

//绑定页面，用于加载页面数据
var app = new Vue({
  el: '#adminBody',
  data: {
    alist: getAdminAll(),
    plist: getAdminPagin(pageIndex, pageSize)
  },
  methods: {
    updataAdmin(id) {
      xadmin.open('编辑', 'admin-edit.html?id=' + id, 600, 400)
    },
    delAdminById(id) {
      layer.confirm('确认要删除吗？', function () {
        $.ajax({
          url: 'http://47.102.45.219:8080/Appoint/adminZoneServlet/deleteUserById',
          data: {
            id: id
          },
          dataType: 'json',
          type: 'post',
          async: false,
          xhrFields: {
            withCredentials: true
          },
          success: function (data) {
            if (data.statu) {
              layer.msg('删除成功', {
                icon: 1,
                time: 1000
              })
              xadmin.father_reload();
            } else {
              layer.msg('删除成功', {
                icon: 0,
                time: 1000
              })
            }
          },
          error: function (XMLHttpRequest, textStatus, errorThrown) {}
        })
      })
    },
    addAdmin() {
      xadmin.open('编辑', 'admin-add.html', 600, 400)
    }


  }
})

var page = new Pagin({
  el: '#myPage',
  dataSize: app.alist.length,
  pageSize: pageSize,
  func: function () {
    app.plist = getAdminPagin(PaginJson.pageIndex, PaginJson.pageSize)
  }
})
//获取管理员用户总表
function getAdminAll() {
  var alist
  $.ajax({
    url: 'http://47.102.45.219:8080/Appoint/adminZoneServlet/getAdminAll',
    dataType: 'json',
    type: 'post',
    async: false,
    xhrFields: {
      withCredentials: true
    },
    success: function (data) {
      alist = data.data
    },
    error: function (XMLHttpRequest, textStatus, errorThrown) {}
  })

  return alist
}

//分页获取管理员总表信息
function getAdminPagin(pageIndex, pageSize) {
  var plist
  $.ajax({
    url: 'http://47.102.45.219:8080/Appoint/adminZoneServlet/getAdminPagin',
    dataType: 'json',
    type: 'post',
    async: false,
    data: {
      pageIndex: pageIndex,
      pageSize: pageSize
    },
    xhrFields: {
      withCredentials: true
    },
    success: function (data) {
      plist = data.data
    },
    error: function (XMLHttpRequest, textStatus, errorThrown) {}
  })

  return plist
}